package com.example.ribbonserver.hystrix;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.web.client.RestTemplate;

/**
 * @author zhanghaidong
 * @version v1.0
 * @description
 * @date 2020/4/22
 */
public class HelloPostCommand extends HystrixCommand<String> {

    private RestTemplate restTemplate;

    private String name;

    public HelloPostCommand(RestTemplate restTemplate, String name) {
        super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("GetSetGet")));
        this.restTemplate = restTemplate;
        this.name = name;
    }

    @Override
    protected String run() throws Exception {
        //写操作
        String getObj = restTemplate.postForObject("URI", null, String.class);

        //清除缓存
        HelloGetCommand.flushCache(name);
        return getObj;
    }
}
